cmake_minimum_required(VERSION 3.16)

project(thickline VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets OpenGL)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets OpenGL)

include_directories("/Users/neo/VulkanSDK/1.3.290.0/macOS/include")
include_directories(".")
include_directories("gpu_engine")

link_directories("/Users/neo/VulkanSDK/1.3.290.0/macOS/lib")

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        defaultpainter.h
        defaultpainter.cpp
        openglpainter.h
        openglpainter.cpp
        mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(thickline
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        gpu_engine/gpu/compute_graph/BufferCopyNode.cpp gpu_engine/gpu/compute_graph/BufferCopyNode.h gpu_engine/gpu/compute_graph/ComputeGraph.cpp gpu_engine/gpu/compute_graph/ComputeGraph.h gpu_engine/gpu/compute_graph/ComputePipelineNode.cpp gpu_engine/gpu/compute_graph/ComputePipelineNode.h gpu_engine/gpu/compute_graph/GraphicsPipelineNode.cpp gpu_engine/gpu/compute_graph/GraphicsPipelineNode.h gpu_engine/gpu/compute_graph/GraphicsRenderPassNode.cpp gpu_engine/gpu/compute_graph/GraphicsRenderPassNode.h gpu_engine/gpu/compute_graph/IComputeGraphNode.h gpu_engine/gpu/compute_graph/ImageToBufferCopyNode.cpp gpu_engine/gpu/compute_graph/ImageToBufferCopyNode.h gpu_engine/gpu/compute_graph/SubComputeGraph.cpp gpu_engine/gpu/compute_graph/SubComputeGraph.h gpu_engine/gpu/utils/vk_enum_string_helper.h gpu_engine/gpu/VkGPUBuffer.cpp gpu_engine/gpu/VkGPUBuffer.h gpu_engine/gpu/VkGPUComputePipeline.cpp gpu_engine/gpu/VkGPUComputePipeline.h gpu_engine/gpu/VkGPUContext.cpp gpu_engine/gpu/VkGPUContext.h gpu_engine/gpu/VkGPUDescriptorSet.cpp gpu_engine/gpu/VkGPUDescriptorSet.h gpu_engine/gpu/VkGPUFramebuffer.cpp gpu_engine/gpu/VkGPUFramebuffer.h gpu_engine/gpu/VkGPUGraphicsPipeline.cpp gpu_engine/gpu/VkGPUGraphicsPipeline.h gpu_engine/gpu/VkGPUHelper.cpp gpu_engine/gpu/VkGPUHelper.h gpu_engine/gpu/VkGPURenderPass.cpp gpu_engine/gpu/VkGPURenderPass.h gpu_engine/gpu/VkGPUSwapChain.cpp gpu_engine/gpu/VkGPUSwapChain.h gpu_engine/log/Log.h gpu_engine/utils/ImageUtils.cpp gpu_engine/utils/ImageUtils.h gpu_engine/utils/IOUtils.cpp gpu_engine/utils/IOUtils.h gpu_engine/utils/TimeUtils.cpp gpu_engine/utils/TimeUtils.h  gpu_engine/config.h gpu_engine/GPUBezierThickLineGenerator.cpp gpu_engine/GPUBezierThickLineGenerator.h
        qvulkanpaintdevice.h qvulkanpaintdevice.cpp
        vulkanpainter.h vulkanpainter.cpp
        qvulkanpaintengine.h qvulkanpaintengine.cpp
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET thickline APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(thickline SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(thickline
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(thickline
  PRIVATE
  Qt${QT_VERSION_MAJOR}::Widgets
  Qt${QT_VERSION_MAJOR}::OpenGL
  vulkan
)

if (APPLE)
  find_library(OPENGL_LIBRARY OpenGL)
  target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARY})
endif()

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.thickline)
endif()
set_target_properties(thickline PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS thickline
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(thickline)
endif()
